--- title: "3、直线" created: 2025-11-28 tags: - 算法 --- # 3、直线 ## 题目 [直线](https://www.lanqiao.cn/paper/3829/problem/1449/) ![[image-27964247.png]] ## 思路分析 ![[image-ee140f90.png]] 每两个点可以确定一条线 但线重合算同一条线 所以可以用哈希去存这些线 可以很好解决重复的问题 问题是如何存下一条线 考虑用 y=kx+b 那么只需要记录k b 即可确定一条线 那么问题就转变成了 枚举每两个点 算他们的kb 存入哈希表中 最后看哈希表的大小即可 另外 斜率不存在的情况 不好处理(斜率公式中 分子为0了) 因为是竖线 所以他和宽度有关 有多少列 就有多少条 拿出来另外处理 ```cpp #include using namespace std; typedef pair PII; set hashtable; int main() { int n,m; n=20,m=21; for(int x1=0;x1 using namespace std; typedef pair PII; set hashtable; int main() { int n,m; n=20,m=21; for(int x1=0;x1